Uec3.PartnerAddressQueryWindow = Ext.extend(Ext.app.Module,{
     id:'partnerAddress_query',
     type:'common/partnerAddressQuery',
      
     selectPartnerAddress : function(id){
		var win = this.curWindow;
		var store = win.get(0).getStore();
		var record = store.getById(id);   						   	   
		var value = record.data;
		this.setLookupValue(value,win);
		var lookup=win.lookup;				      
		if(lookup.lookupCallBackEvents){
			Ext.each(lookup.lookupCallBackEvents,function(event){
				if(event == 'lookupChange'){
					lookup.fireEvent(event,record);
				}else{
					lookup.fireEvent(event);
				}
			});
		}				      
		win.close();
	},
     
     getPanel:function(param){   
     	var module = this;
     	  
      var partnerAdress_record = Ext.data.Record.create([    
			 {name:'areaId',type : 'string',mapping:'areaId'},
			 {name:'province',type : 'string',mapping:'province'},
			 {name : 'city',type : 'string',mapping:'city'},			
			 {name : 'district',type : 'string',mapping:'district'},
			 {name : 'street',type : 'string',mapping:'street'},
			 {name : 'postCode',type : 'string',mapping:'postCode'},
			 {name : 'receiverName',type : 'string',mapping:'receiverName'},
			 {name : 'phone',type : 'string',mapping:'phone'},
			 {name : 'mobile',type : 'string',mapping:'mobile'}]
	  )
     
      var partnerAddress_ds = new Ext.data.JsonStore({
     	       url : Uec3.App.Constants.homeUrl+ '/partnerAddress/query_partnerAddress!query.do',
     	       root: 'root',
			   fields:partnerAdress_record,
			   listeners :{
			   	  'load':function(store,records,options){	
			   	  	  if(records.length == 0){
			   	  		  Ext.MessageBox.alert("提示","未建立过该客户的地址,请先创建");
			   	  		  module.curWindow.close();
			   	  	  }else{
			   	  	  	  Ext.each(records,function(record,index,array){
		  	   	             var address = '地址:' + (record.data.province ? record.data.province : '') + (record.data.city ? record.data.city : '') + 
		  	   	             	(record.data.district ? record.data.district : '') + (record.data.street ? record.data.street : '') + 
		  	   	             	(record.data.receiverName ? ";联系人:" + record.data.receiverName : '') + 
		  	   	             	(record.data.phone ? ";电话:" + record.data.phone : '') + 
		  	   	             	(record.data.mobile ? ";手机:" + record.data.mobile : '');			  	   	   
		  	                 record.set('address',address);
		  	              });
			   	  	  }		  	          
		            }
			   }
      });
      
      var partnerAddress_selectModel = new Ext.grid.CheckboxSelectionModel({
    	    checkOnly : true,
    	    moveEditorOnEnter : true,
    	    singleSelect : true
      }); 
     	
     	var partnerAddress_colModel = new Ext.grid.ColumnModel([
     	         {header : "操作",width : 35,dataIndex : 'areaId',
	           	  renderer:function(value,meta,record,rowIndex,colIndex,store){
	            		var str="<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\""+module.id+"\").selectPartnerAddress("+record.id+");'>选中</a>"
	            	  	return str;}
    	         },
				 {header : "地区",hidden:true,width : 60,dataIndex : 'areaId'},
				 {header : "省份",width : 60,dataIndex : 'province'},
				 {header : "城市",width : 60,dataIndex : 'city'},   
				 {header : "区域",width : 60,dataIndex : 'district'},
				 {header : "详细地址",width : 80,dataIndex : 'street'},				  
				 {header : "邮编",width : 80,dataIndex : 'postCode'}, 
				 {header : "收货人姓名",width : 80,dataIndex : 'receiverName'},
				 {header : "电话",width : 80,dataIndex : 'phone'}, 
				 {header : "手机",width : 60,dataIndex : 'mobile'}
		]);	
          
		 var module=this;
		
     	 var partnerAddress_grid = new Ext.grid.GridPanel({
				disableSelection:true,
				//title: '客户收货地址',
				store:partnerAddress_ds,
				enableHdMenu : false,
				height:315,
				cm:partnerAddress_colModel,
				viewConfig :{
						forceFit : true					
				 },
				selModel:new Ext.grid.RowSelectionModel({moveEditorOnEnter:true,singleSelect:true}),
				iconCls : 'icon-grid',
				loadMask : {msg : '数据加载中...'},
				stripeRows: true,
				autoScroll: true,
				listeners : {
				   rowdblclick:function(grid,rowIndex,e){
				   	   var record = grid.getStore().getAt(rowIndex);				   	  
				   	   var win =param.desktopModule.curWindow;				   	   
				   	   //var value = {'areaId':record.data.areaId,'address':record.data.province+record.data.city+record.data.district+record.data.street+','+record.data.receiverName+','+record.data.phone+','+record.data.mobile};
				       var value = record.data;
				   	   module.setLookupValue(value,win);
				       var lookup=win.lookup;				      
				       if(lookup.lookupCallBackEvents){
				       	  Ext.each(lookup.lookupCallBackEvents,function(event){
				       		  if(event == 'lookupChange'){
				       			 lookup.fireEvent(event,record);
				       		  }else{
				       			 lookup.fireEvent(event);
				       		  }
				       	  });
				       }
				       win.close();
				   }
				}
           });	
       
		init();
		
		function init(){
	         partnerAddress_ds.baseParams = {partnerId : param.partnerId ? param.partnerId : param.partnerCmb.getValue()};
	         partnerAddress_ds.load();
		}
		
	    return partnerAddress_grid;
      },

     createWindow:function(param){     
     	
     		var partnerId = param.partnerId ? param.partnerId : param.partnerCmb.getValue();
		    if(Ext.isEmpty(partnerId)){
		         Ext.MessageBox.alert('提示','请选择采购单位');
		    	 return;
		    }
     	
          var desktop = this.app.getDesktop();
    	  var win = desktop.getWindow("partnerAddress_query");
    	  if(!win){    		
    	  	win = desktop.createWindow({
            id: "partnerAddress_query",   
            modal : true,
            title: '客户地址查询',
            width: 800,
            height: 350,
            minWidth:800,
            minHeight:350,
            autoScroll : false,
            iconCls: 'acc-icon',
            shim: false, 
            animCollapse: false,
            constrainHeader: true,
            maximizable: true,  
            minimizable : false,
            items:[this.getPanel(param)]         
         });        
       }
       win.show();
      /* win.on("show",function(){
          var view_panel = this.getPanel(param);    
	      win.add(view_panel);
          win.doLayout();               
       },this);*/
       
       win.on('resize',function(win,width,height){     	
      	  win.get(0).setHeight(height);
       });
    }
}); 